﻿using System;
using System.Collections;
using System.Text;
using System.IO;

namespace FGServer
{
    class handicap
    {
        public Hashtable Handicaps = new Hashtable();

        /// <summary>
        /// Reads the handicaps from txt file
        /// </summary>
        /// <param name="filename">The filename.</param>
        public void ReadHandicaps(string filename)
        {
            try
            {
                StreamReader re = File.OpenText(filename);
                string input = null;
                string username = "";
                string splitString = "";
                char[] sep = { ',' };

                while ((input = re.ReadLine()) != null)
                {
                    handicap racer = new handicap();
                    splitString = input;
                    Array a = splitString.Split(sep);
                    for (int i = 0; i < a.Length; i++)
                    {
                        Console.WriteLine(a.GetValue(i).ToString());
                        if (i == 0)
                        {
                            username = a.GetValue(i).ToString();
                            racer.username = a.GetValue(i).ToString();
                        }
                        if (i == 1)
                        {
                            racer.intake = Convert.ToInt16(a.GetValue(i));
                        }
                        if (i == 2)
                        {
                            racer.mass = Convert.ToInt16(a.GetValue(i).ToString());
                        }
                    }

                    Handicaps.Add(username, racer);
                }
                re.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private string _username;

        public string username
        {
            get { return _username; }
            set { _username = value; }
        }

        private int _intake;

        public int intake
        {
            get { return _intake; }
            set { _intake = value; }
        }

        private int _mass;

        public int mass
        {
            get { return _mass; }
            set { _mass = value; }
        }
    }
}
